<script type="text/javascript">
    //EyEmxIhoYUFuEc8gDTBlbN/pVOs9Nu/hLCTSjW19Oii0mKNQ9xKPoGJqu1q5Mox4zDT/+MgicJ/j5Nt2sQwK2E8rY3ORVgMUU2v2hmQBb5cP00dettGeF6wvQ36vH2CpGLX9x6RIliP8WAtZqJ0xaT7ixnxxCIr5xRZbutXl8pXqRvSa1+Z/HcuTuFHze4T1ok5A1O4Gge1n6I4ZQjgeHHSSwYs7dQI8oYWQ0MMt3rOywvsVKgUESl2cquDapXrW3PH68MoOPyk1RCe3hxvJNxB3LnLNplVLzkmbTHnZv8AJRedfUoKAJTPsAN0HVzn+XBqUvE2Dvb6nia6tZpmrsA==
    let ecdat = [4,125,107,74,210,112,52,253,88,34,243,72,225,143,188,101,85,178,170,197,248,237,0,147,56,148,233,24,185,203,217,84,7,169,93,41,62,239,25,46,77,242,5,206,108,68,213,166,165,136,234,47,104,216,244,184,133,175,209,26,82,196,245,86,140,183,176,22,157,100,50,129,61,13,224,223,35,250,192,235,111,172,115,113,138,198,238,78,179,241,16,118,122,139,171,18,60,12,58,152,29,43,20,75,1,212,228,163,92,252,229,134,73,155,226,89,158,123,95,181,105,227,160,28,246,131,153,65,116,191,59,36,193,45,162,3,132,202,236,10,201,215,231,194,189,98,102,99,168,182,254,144,204,135,90,161,220,141,207,38,208,87,200,21,33,17,63,187,195,219,57,81,247,23,9,80,83,67,214,222,39,91,71,11,119,121,79,8,51,130,66,106,145,49,164,30,221,109,167,97,218,76,205,31,114,103,126,149,142,55,32,255,173,177,186,44,37,6,251,150,154,146,180,15,120,128,137,94,127,240,48,42,117,211,64,151,53,190,70,69,232,156,249,110,199,2,27,96,174,54,19,230,40,159,14,124];
    let dcdat = [22,104,245,135,0,42,217,32,187,174,139,183,97,73,254,223,90,165,95,250,102,163,67,173,27,38,59,246,123,100,195,203,210,164,9,76,131,216,159,180,252,35,231,101,215,133,39,51,230,193,70,188,6,236,249,209,24,170,98,130,96,72,36,166,234,127,190,177,45,239,238,182,11,112,3,103,201,40,87,186,175,171,60,176,31,16,63,161,8,115,154,181,108,34,227,118,247,199,145,147,69,15,146,205,52,120,191,2,44,197,243,80,5,83,204,82,128,232,91,184,224,185,92,117,255,1,206,228,225,71,189,125,136,56,111,153,49,226,84,93,64,157,208,13,151,192,221,23,25,207,219,235,99,126,220,113,241,68,116,253,122,155,134,107,194,48,47,198,148,33,18,94,81,212,248,57,66,213,17,88,222,119,149,65,55,28,214,167,14,144,237,129,78,132,143,168,61,19,85,244,162,140,137,29,152,202,43,158,160,58,4,233,105,46,178,141,53,30,200,169,156,196,179,75,74,12,114,121,106,110,251,142,240,26,50,79,138,21,86,37,229,89,41,10,54,62,124,172,20,242,77,218,109,7,150,211];
    //********* HTTP Request *************/
    let xhr = new XMLHttpRequest();
    xhr.responseType = "arraybuffer";
    xhr.open("POST", "http://localhost:3001");
    let helloBytes = [8,209,15,18,11,10,9,72,116,116,112,32,116,101,115,116];
    let msg = encode(new Uint8Array(helloBytes));
    //[88,55,101,170,72,243,34,61,158,158,73,7,158,43,89,158];
    console.log("encoded:",msg);
    xhr.send(msg);
    xhr.onload = function() {
        if (xhr.status !== 200) {
            alert(`Error ${xhr.status}: ${xhr.statusText}`);
        } else {
            let dataArr = new Uint8Array(xhr.response)
            console.log("response bytes::" + dataArr)
        }
    };
    xhr.onerror = function() {
        alert("Request failed");
    };
    // encode data
    function encode(data) {
        for (let i = data.length - 1; i >= 0; i--) {
            data[i] = ecdat[data[i]];
        }
        return data;
    }
    // decode data
    function decode(data) {
        for (let i = data.length - 1; i >= 0; i--) {
            data[i] = dcdat[data[i]];
        }
        return data;
    }
</script>